package ups.glre.news.dao.impl;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.Query;

import ups.glre.news.dao.CategoryDAO;
import ups.glre.news.model.Category;

@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class CategoryDAOImpl extends GenericDAOImpl<Category,Integer> implements CategoryDAO{

	@Override
	public Category findCategoryByName(String categoryName) {
		Query q = entityManager.createQuery("SELECT e FROM "
				+ entityClass.getName() + " e WHERE categoryName = :categoryName ");
		
		q.setParameter("categoryName", categoryName);
		
		return (Category) q.getSingleResult();
	}
}
